
public class DLL<T> implements IDLL<T> {
	
	
	 private int size;      	/** list size, counting head and tail */
	 private DLLNode<T> head; 		/** the head node of the list         */
	 private DLLNode<T> tail; 		/** the tail node of the list         */
	

	 //default constructor, list always has 2 nodes (head, tail)
	 public DLL(){
			size=2;
			head=new DLLNode();
			tail=new DLLNode();
			head.setNext(tail);
			tail.setPrev(head);
			
			
		}
		
		
		//accessors and mutators
		public DLLNode<T> getHead(){
			return head;
		}
		public void setHead(DLLNode<T> newHead){
			head=newHead;
		}
		public int getSize(){
			return size;
		}
		public void setSize(int what){
			size=what;
		}
		public DLLNode<T> getTail(){
			return tail;
		}
		public void setTail(DLLNode<T> newTail){
			tail=newTail;
		}
		

	@Override
	public boolean add(T dllData) {
		DLLNode<T> newNode=new DLLNode(dllData,null);
		
		newNode.setNext(head.getNext());
		newNode.setPrev(head);
		
		head.setNext(newNode);
		
		newNode.getNext().setPrev(newNode);
		
		this.setSize(size+1);	//increments size
		return true;
	}

	@Override
	public boolean addAtHead(T dllData) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean contains(T dllData) {
		int dllSize=this.getSize();
		DLLNode<T> temp=head;
		
		for(int i=0; i<dllSize; i++){
			if(temp.getNodeData()!=null){
			if(temp.getNodeData().equals(dllData)){
					
				return true;
			}
			
			}
			
				//goes to next node in list, provided it isn't the tail
			if(temp.getNext()!=null){
			temp=temp.getNext();
				
			}
		}
		return false;
	}

	

	@Override
	public boolean remove(T dllData) {
		
		DLLNode<T> temp=head.getNext();
		
		while(temp!=tail){
			if(temp.getNodeData()!=null){
			
				//if match is found node is unlinked from list
			if(temp.getNodeData().equals(dllData)){
				DLLNode<T> next=temp.getNext();
				DLLNode<T> prev=temp.getPrev();
				
				next.setPrev(prev);
				prev.setNext(next);
				
				temp.setNext(null);
				temp.setPrev(null);
				temp.setNodeData(null);
				
				
				this.setSize(size-1);		//decrements size
				return true;
			}
			}
			//goes to next node in list
			if(temp.getNext()!=null){
				
				temp=temp.getNext();	
			}
			
			}
			
		return false;
	}

	

}
